package com.kk.model;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
public class Role extends BaseEntity{

    private String name;//角色名称
    private String roledesc;//角色描述

    //多对多在两边都需要设置为立刻加载模式，一对多则只需要在一的这边设置为立刻加载模式
    //cascade:级联，fetch:FetchType.EAGER:立刻加载;FetchType.LAZY:懒加载
    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    @JoinTable(name = "role_permission", joinColumns = {
            @JoinColumn(name = "role_id", referencedColumnName = "id")}, inverseJoinColumns = {
            @JoinColumn(name = "permission_id", referencedColumnName = "id")})
    private Set<Permission> permissions;//角色权限关系  多对多  一个角色对应多个权限

    public Role(){
    }
    public Role(String name){
        this.name = name;
    }
}
